#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<stdlib.h>

//int main()
//{
//	int num;
//	int i = 0;
//	while (scanf("%d", &num) != EOF)
//	{
//		i++;
//		if (num == 250)
//		{
//			printf("%d", i);
//			break;
//		}
//	}
//	return 0;
//}
//int main()
//{
//	int mm, dd, yyyy;
//	scanf("%d-%d-%d", &mm, &dd, &yyyy);
//	printf("%d-%02d-%02d", yyyy, mm, dd);
//	return 0;
//}
typedef struct time
{
	int tite;
	char give;
	int hour;
	int min;
}time;

typedef struct QList
{
	time* data;
	int size;
	int capcity;
}QList;

void QListInit(QList* a)
{
	a->data = NULL;
	a->size = 0;
	a->capcity = 0;
}

void QListPush(QList* a, time x)
{
	if (a->size == a->capcity)
	{
		a->capcity = a->capcity == 0 ? a->capcity = 4 : a->capcity * 2;
		time* next = realloc(a->data, sizeof(time)*a->capcity);
		if (next == NULL)
		{
			perror("realloc fail");
			exit(-1);
		}
		a->data = next;
	}
	a->data[a->size].tite = x.tite;
	a->data[a->size].give = x.give;
	a->data[a->size].hour = x.hour;
	a->data[a->size].min = x.min;
	a->size++;
}
void QListDestory(QList* a)
{
	free(a->data);
	a->size = 0;

}
time* QListFind(QList* a, int  x)
{
	for (int i = 0; i < a->size; i++)
	{
		if (a->data[i].tite == x)
			return a->data + i;
	}
	return NULL;
}
int main()
{
	
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		QList as;
		QList ae;

		QListInit(&as);
		QListInit(&ae);

		time data = { 0 };

		do
		{
			scanf("%d %c %d:%d", &data.tite, &data.give, &data.hour, &data.min);
			if(data.tite!=0)
			{
				if (data.give == 'S')
					QListPush(&as, data);
				else
					QListPush(&ae, data);
			}

		} while (data.tite);
		int sum = 0;
		int _time = 0;
		for (int i = 0; i < as.size; i++)
		{
			time* _data;
			if (_data = QListFind(&ae, as.data[i].tite))
			{
				sum++;
				_time += (_data->hour - as.data[i].hour) * 60 + (_data->min - as.data[i].min);
			}
		}
		if (sum != 0)
		{
			double k = (_time / (double)sum) + 0.5;
			printf("%d %d\n", sum, (int)k);
		}
		else
			printf("0 0\n");

		QListDestory(&as);
		QListDestory(&ae);

	}
	
	return 0;
}